// const BASE_URL = 'http://127.0.0.1:5001/api'
const BASE_URL = 'http://192.168.101.163:5001/api'

export default function request(option) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + option.url,
			data: option.data || {},
			method: option.method || 'GET',
			header: {
				'Content-Type': 'application/json',
				'Authorization': uni.getStorageSync('token')
			},
			success: res => {
				const data = res.data

				if (data.code === 11002 || data.code === 11001) {
					uni.removeStorageSync('token')
					return
					// uni.showToast({
					// 	icon: 'none',
					// 	title: data.message || '登录已过期，请重新登录'
					// });
				} else if (data.code !== 200) {
					uni.showToast({
						icon: 'none',
						title: res.data.message || '请求错误'
					})
				}
				resolve(res.data)
			},
			fail: err => {
				reject(err)
			}
		})
	})
}